<?php
	require './config/config.php';
	session_start();
	if(empty($_SESSION['member'])){
        echo "<script>location='../index.php';</script>";
    }
	$ConfigSql="select * from config where id='1'";
	$ConfigInfo=mysqli_query($con,$ConfigSql);
	$ConnfigRs=mysqli_fetch_array($ConfigInfo);
	if($_GET['ops']=="logout"){
	    $_SESSION['member']="";
	    session_destroy();
	    echo "<script>alert('您已退出登录！');location='./index.php';</script>";
	}
	if(!empty($_SESSION['member'])){
	    //$UserSql=mysqli_query($con,"select * from member while user='".$_SESSION['member']."'");
		//$UserInfo=mysqli_fetch_array($UserSql);
		$UserSql="SELECT * FROM `member` WHERE user='".$_SESSION['member']."'";
		$UserInfo=mysqli_query($con,$UserSql);
		@$UserRs=mysqli_fetch_array($UserInfo);
		//echo "<script>alert('".$UserInfo['type']."');</script>";
	}
	if(empty($_GET['id'])){
	    echo "<script>alert('未定义id！');location='./index.php';</script>";
	}else{
	    $rs=mysqli_fetch_array(mysqli_query($con,"select * from feedback where id='".$_GET['id']."'"));
	    if($rs['id']==""){
	        echo "<script>alert('文章不存在！');location='./index.php';</script>";
	    }
	}
	if($_POST){
	    $content = $_POST['content'];
	    if($content==""){
	        //echo "<script>alert('系统异常，暂时无法为您提供服务！');history.back();</script>";
	    }else{
	        $ip=getip();
	    	$result=mysqli_query($con,"INSERT INTO `comment` (`id`, `user`, `admin`, `connect`, `ip`, `date`, `feedbackid`) VALUES (null, '".$_SESSION['member']."', '0', '".$content."', '".$ip."', '".date("Y/m/d H:i:s")."', '".$_GET['id']."');");
	    	//INSERT INTO `comment` (`id`, `user`, `admin`, `connect`, `ip`, `date`, `feedbackid`) VALUES ('2', '1', '1', '1', '1', '1', '1');
	    	if($result){
	    	    echo "<script>alert('成功发布评论！');location='./show.php?id=".$_GET['id']."';</script>";
	    	}else{
	    	    echo "<script>alert('系统异常，暂时无法发布评论！');history.back();</script>";
	    	}
	    }
	}
?>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title><?php echo $ConnfigRs['name'];if($ConnfigRs['title']!=""){echo " - ".$ConnfigRs['title'];}?></title>
	    <link rel="stylesheet" type="text/css" href="css/index.css">
    </head>
<body>
<div class="dvhead">
	<div class="dvlogo"><a href="index.php"><?php echo $ConnfigRs['name'];?></a></div>
	<div class="dvreg">
		<?php
		    if(empty($_SESSION['member'])){
                echo "已有账号，立即&nbsp;<a href='login.php'>登录</a>";
            }else{
                echo "欢迎您，".$_SESSION['member']." &nbsp;&nbsp;<a href='?ops=logout'> 退出</a>";
            }
		?>
	</div>
</div>
<div class="dvContent">
	<div class="dvquesleft">
		<div class="tabContent">
			<div class="tab">
		        <div class="dvques">
					<div class="quesContent">
						<?php 
						    echo $rs['title'];?><br /><br />发布者：<?php echo $rs['adduser'];?> | 发布时间：<?php echo $rs['addtime'];
						?>
						
					</div>
					<div class="qContent">
					    <?php echo $rs['content'];?>
					</div>
				</div>
				<?php
				if(!empty($_SESSION['member'])){
				    $Group=mysqli_fetch_array(mysqli_query($con,"select * from member where user='".$_SESSION['member']."'"));
    			    if($_SESSION['member']==$rs['adduser']){
    			        echo "<h4><a href='./pay/index.php?id=".$_GET['id']."'>关联订单</a>";
    			    }elseif($Group['type']=="1" || $Group['type']=="2"){
    			        echo "<h4><a href='./pay/userOrder.php?id=".$_GET['id']."'>关联订单</a>";
    			    }
    			    if($Group['type']=="1" || $Group['type']=="2"){
    			        echo " | <a href='./pay/newpay.php?id=".$_GET['id']."'>发起支付订单</a></h4>";
    			    }else{
    			        echo "</h4>";
    			    }
			    ?>
				    
			        <form method="post" action="./show.php?id=<?php echo $_GET['id'];?>">
            			<table class="news-edit">
        					<tr>欢迎您，<?php echo $_SESSION['member'];?> ：<br /><br /></tr>
        					<tr><textarea rows="10" cols="90" name="content" placeholder="填写评论内容..."></textarea><br /></tr>
        					<tr><input class="btnques" type="submit" value="发布评论" /></tr>
            			</table>
            		</form>
			    <?php }?>
				<?php
				    echo "<br /><h2>回复：</h2><br />";
		            $commentsql="select * from comment where feedbackid='".$rs['id']."'  order by id asc";//asc desc
    				$commentresult=mysqli_query($con,$commentsql);
    				$total=mysqli_num_rows($commentresult);
				    if($total>0){
				        while($commentrs=mysqli_fetch_array($commentresult)){  
				            
				        ?>
				            <table class="news-edit">
                					<tr>
            					    <?php 
                                    	$GroupRs=mysqli_fetch_array(mysqli_query($con,"select * from member where user='".$commentrs['user']."'"));
                                    	if($GroupRs['type']=="1" or $GroupRs['type']=="2"){
                                    	    echo "<font color='red'>".$commentrs['user']."(管理员)</font>";
                                    	}else{
                                    	    echo $commentrs['user'];
                                    	}
            					    ?>：
            					</tr>
            					<tr><?php echo $commentrs['connect'];?><br />回复时间：<?php echo $commentrs['date'];?></tr>
                			</table>
                			<br />
                			<hr />
                			<br />
				        <?php }
				    }else{
				        echo "暂时没有回复！";
				    }
				?>
			</div>
		</div>
	</div>
	<div class="dvquesright">
		<div>
			<buton class="btnques" onclick="location.href='add.php'">提个问题</buton>
		</div>
		<br />
		<br />
		<div>
			<buton class="btnques" onclick="location.href='add.php'">我的订单</buton>
		</div>
		<br />
		<br />
		<div>
			<buton class="btnques" onclick="location.href='add.php'">个人信息</buton>
		</div>
	</div>

</div>
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
	$(function()
	{

		$(".tabheads").click(function()
		{
			$(".tabheads").removeClass("tabcurrent").eq($(this).index()).addClass("tabcurrent");
			$(".tab").hide().eq($(this).index()).show();
		});
	});
</script>
</body>
</html>

